package com.flyan.game.motafx.effect.item;

import com.almasb.fxgl.entity.Entity;
import com.flyan.game.motafx.component.LifePanelComponent;
import com.flyan.game.motafx.core.enums.EntityTypeEnum;
import com.flyan.game.motafx.core.util.entity.EntityUtils;
import com.flyan.game.motafx.effect.BaseEffect;
import javafx.util.Duration;
import org.jetbrains.annotations.NotNull;

/**
 * 宝石道具效果
 *
 * @author flyan
 * @version 1.0
 * @email flyan_by_chenu@sina.com
 * @since 2025/2/7
 */
public class GemEffect extends BaseEffect {

    public GemEffect() {
        super(Duration.seconds(0.1));
    }

    @Override
    public void onStart(@NotNull Entity entity) {
        EntityTypeEnum itemType = (EntityTypeEnum) triggerEntity.getType();
        LifePanelComponent lifePanelComponent = entity.getComponent(LifePanelComponent.class);
        Integer value = EntityUtils.getEntityProperty(triggerEntity, "properties.value", Integer.class);
        switch (itemType) {
            case ITEM_RED_GEM -> lifePanelComponent.getLifePanel().increaseAck(value);
            case ITEM_BLUE_GEM -> lifePanelComponent.getLifePanel().increaseDef(value);
        }
        lifePanelComponent.update();
    }

    @Override
    public void onEnd(@NotNull Entity entity) {

    }

}
